package com.itheima.manager.StudentService;

import com.itheima.manager.Student.Student;
import com.itheima.manager.StudentDao.StudentDao;

public class StudentService {
    StudentDao studentDao = new StudentDao();

    public void addStudent(Student stu) {
        studentDao.addStudent(stu);

    }


    public boolean Exist(String id) {
        Student[] stus = studentDao.findAllStudent();
        for (int i = 0; i < stus.length; i++) {
            Student st = stus[i];
            if (st != null && st.getId().equals(id)) {

                return true;
            }
        }
        return false;

    }

    public Student[] findStudent() {
        boolean flag = false;
        Student[] students = studentDao.findAllStudent();
        for (int i = 0; i < students.length; i++) {
            if (students[i] != null) {
                flag = true;
                break;
            }
        }
        if (flag) {
            return students;
        } else {
            return null;
        }
    }

    public boolean deletStudent(String id) {
        Student[] students = studentDao.findAllStudent();
        boolean flag = false;
        for (int i = 0; i < students.length; i++) {
            Student stus = students[i];
            if (stus.getId().equals(id)) {
                flag = true;
                studentDao.deletStudent(id);
                break;
            }
        }
        return flag;
    }

    public boolean isExist(String id) {
        Student[] students = studentDao.findAllStudent();
        boolean flag = false;
        for (int i = 0; i < students.length; i++) {
            Student stus = students[i];
            if (stus != null && stus.getId().equals(id)) {
                flag = true;
                break;
            }
        }
        return flag;
    }

    public void updateStudent(Student stu) {
        studentDao.updateStudent(stu);
    }
}




